package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.CalculEstimation;
import metier.entities.ImageSite;


@Stateless(name="ImageSite")
public class ImageSiteEJBImpl implements IImageSiteLocal{
	@PersistenceContext(unitName="PU_Cargaison")
	private EntityManager em;
	
	
	@Override
	public void addImageSite(ImageSite img) {
		em.persist(img);
		
	}

	@Override
	public List<ImageSite> getAllImageSite() {
		Query req=em.createQuery("select img from ImageSite img");
		return req.getResultList();
	}

	@Override
	public ImageSite getImageSite(Integer Id) {
		ImageSite de=em.find(ImageSite.class, Id);
		if(de==null)throw new RuntimeException("Image introuvable");
		return de;
	}

	@Override
	public void updateImageSite(ImageSite img) {
		em.persist(img);
	}

	@Override
	public void deleteImageSite(Integer Id) {
		em.remove(getImageSite(Id));
		
	}

}
